package com.team11.server.controller.admin;
import com.team11.server.service.admin.Admin_DeleteSInP_Service;
import com.team11.server.service.admin.Admin_UpdatePleader_Service;
import com.team11.server.service.admin.Admin_UpdateSInP_Service;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

@CrossOrigin
@Api(tags = "管理员接口")
@RestController
public class Admin_DeleteAllSInP_Controller {
    @Autowired
    private Admin_DeleteSInP_Service admin_deleteSInP_service;
    @Autowired
    private Admin_UpdateSInP_Service admin_updateSInP_service;
    @Autowired
    private Admin_UpdatePleader_Service admin_updatePleader_service;
    @ApiOperation("批量删除项目组学生(需学号与项目组id)")
    @PostMapping("/deleteAllSInP")
    public String deleteAllSInP(@RequestParam(value = "sNumbers" ,required=false)List<String> sNumbers, Integer pId){
        HashMap<String,Object> map=new HashMap<>();
        map.put("pId",pId);
        map.put("NewPid",pId);
        for(String sNumber:sNumbers){
            map.put("sNumber",sNumber);
            String s=admin_updatePleader_service.SelSInP(map);
            if ("1".equals(s)) {
                if(sNumber.equals(admin_updateSInP_service.SelPleader(pId))){
                    admin_updateSInP_service.UpdatePleader(pId);
                }
                 admin_deleteSInP_service.deleteSInP(map);
            }
            else return s;
        }
        return "删除成功";
    }
}
